package com.jsh.controller;

import com.jsh.pojo.AddressBook;
import com.jsh.pojo.Admin;
import com.jsh.service.AddressBookService;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;
@Controller
@RequestMapping("/AddressBook")
public class AddressBookController {

    @Autowired
    AddressBookService addressBookService;
    @RequestMapping("/list")
    public String list(Model model){
        List<AddressBook> addressBooks = addressBookService.selectAll();
        model.addAttribute("list",addressBooks);
        return "list_AddressBook";
    }
    @RequestMapping("/toUpdate")
    public String toUpdate(int contactId,Model model){
        AddressBook addressBook = addressBookService.selectByPrimaryKey(contactId);
        model.addAttribute("addressBook",addressBook);
        return "update_AddressBook";
    }
    @RequestMapping("/update")
    public String update(AddressBook addressBook){
        addressBookService.updateByPrimaryKey(addressBook);
        return "redirect:/AddressBook/list";
    }
    @RequestMapping("/delete")
    public String delete(int contactId){
        int i = addressBookService.deleteByPrimaryKey(contactId);
        return "redirect:/AddressBook/list";
    }
    @RequestMapping("/toInsert")
    public String toInsert(){
        return "addAddressBook";
    }
    @RequestMapping("/insert")
    public String Insert(AddressBook addressBook){
        int insert = addressBookService.insert(addressBook);
        return "redirect:/AddressBook/list";
    }
}
